package com.geovis.emergency.spd.biz.resources.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.geovis.emergency.spd.biz.resources.mapper.BsZhxxdwryMapper;
import com.geovis.emergency.spd.biz.resources.service.BsZhxxdwryService;
import com.geovis.emergency.spd.entity.resources.dto.BsZhxxdwryDetailDTO;
import com.geovis.emergency.spd.entity.resources.dto.ResourceListDTO;
import com.geovis.emergency.spd.entity.resources.entity.BsZhxxdwry;
import com.geovis.emergency.spd.entity.system.entity.SystemFileBusiness;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
@RequiredArgsConstructor
@DS("buffer")
public class BsZhxxdwryServiceImpl extends ServiceImpl<BsZhxxdwryMapper, BsZhxxdwry> implements BsZhxxdwryService {
    @Override
    public List<ResourceListDTO> getZhxxdwry() {
        List<ResourceListDTO> listDTOS=new ArrayList<>();

        ResourceListDTO jd1=new ResourceListDTO();
        jd1.setTitle("上马街道")
                .setTypeName("灾情信息员")
                .setLatitude(Double.parseDouble("36.28"))
                .setLongitude(Double.parseDouble("120.24"));

        ResourceListDTO jd2=new ResourceListDTO();
        jd2.setTitle("城阳街道")
                .setTypeName("灾情信息员")
                .setLatitude(Double.parseDouble("36.31"))
                .setLongitude(Double.parseDouble("120.40"));

        ResourceListDTO jd3=new ResourceListDTO();
        jd3.setTitle("夏庄街道")
                .setTypeName("灾情信息员")
                .setLatitude(Double.parseDouble("36.26"))
                .setLongitude(Double.parseDouble("120.46"));

        ResourceListDTO jd4=new ResourceListDTO();
        jd4.setTitle("惜福镇街道")
                .setTypeName("灾情信息员")
                .setLatitude(Double.parseDouble("36.31"))
                .setLongitude(Double.parseDouble("120.49"));

        ResourceListDTO jd5=new ResourceListDTO();
        jd5.setTitle("棘洪滩街道")
                .setTypeName("灾情信息员")
                .setLatitude(Double.parseDouble("36.34"))
                .setLongitude(Double.parseDouble("120.28"));

        ResourceListDTO jd6=new ResourceListDTO();
        jd6.setTitle("河套街道")
                .setTypeName("灾情信息员")
                .setLatitude(Double.parseDouble("36.25"))
                .setLongitude(Double.parseDouble("120.16"));

        ResourceListDTO jd7=new ResourceListDTO();
        jd7.setTitle("流亭街道")
                .setTypeName("灾情信息员")
                .setLatitude(Double.parseDouble("36.25"))
                .setLongitude(Double.parseDouble("120.40"));



        ResourceListDTO jd8=new ResourceListDTO();
        jd8.setTitle("红岛街道")
                .setTypeName("灾情信息员")
                .setLatitude(Double.parseDouble("36.21"))
                .setLongitude(Double.parseDouble("120.26"));
        listDTOS.add(jd1);
        listDTOS.add(jd2);
        listDTOS.add(jd3);
        listDTOS.add(jd4);
        listDTOS.add(jd5);
        listDTOS.add(jd6);
        listDTOS.add(jd7);
        listDTOS.add(jd8);

        return listDTOS;
    }

    @Override
    public List<BsZhxxdwryDetailDTO> getZhxxdwryDetail(String streetName) {
        LambdaQueryWrapper<BsZhxxdwry> wrapper = Wrappers.<BsZhxxdwry>lambdaQuery()
                .eq(StringUtils.hasText(streetName),BsZhxxdwry::getTownship, streetName);
        List<BsZhxxdwry> zhxxdwries=this.list(wrapper);
        return zhxxdwries.stream().map(zhxxdwry->{
            BsZhxxdwryDetailDTO detailDTO=new BsZhxxdwryDetailDTO();
            BeanUtils.copyProperties(zhxxdwry,detailDTO);
            detailDTO.setName(zhxxdwry.getUserName())
                    .setType(zhxxdwry.getUserType())
                    .setJob(zhxxdwry.getUserJob())
                    .setPhone(zhxxdwry.getUserPhone())
                    .setGender(zhxxdwry.getSex());
            return detailDTO;
        }).collect(Collectors.toList());
    }
}
